package pattern.composite;

import java.util.ArrayList;
import java.util.Iterator;

public class Folder extends FileComponent {
	private ArrayList<FileComponent> list = new ArrayList<FileComponent>();
	
	private String name;
	
	public Folder(String name){
		this.name = name;
	}
	
	@Override
	public String getName() {
		return name;
	}
	
	@Override
	public String getFileType() {
		return "folder";
	}
	
	@Override
	public void add(FileComponent fc) {
		list.add(fc);
	}
	
	@Override
	public void remove(FileComponent fc) {
		list.remove(fc);
	}
	
	@Override
	public FileComponent getChild(int i) {
		return list.get(i);
	}
	
	@Override
	public void print() {
		System.out.println(name);
		System.out.println("----------");
		
		Iterator<FileComponent> it = list.iterator();
		while(it.hasNext()){
			it.next().print();
		}
	}
	
	@Override
	public Iterator<FileComponent> createIterator() {
		return new CompositeIterator(list.iterator());
	}
}
